<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.config</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript"></script>
    <script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
    
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_config_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.4 Documentation</a></li><li>Spec</li><li>Spec - howl.config</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.config">howl.config</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">reset</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">app</span><span class="p">.</span><span class="n">editor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span></pre>&#x000A;&#x000A;<h4 id="reset-clears-all-set-values,-but-keeps-the-definitions">reset clears all set values, but keeps the definitions</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'var'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'var'</span><span class="p">,</span><span class="w"> </span><span class="s1">'set'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">reset</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">definitions</span><span class="p">[</span><span class="s1">'var'</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">get</span><span class="w"> </span><span class="s1">'var'</span></pre>&#x000A;&#x000A;<h4 id="global-variables-can-be-set-and-get-directly-on-config">global variables can be set and get directly on config</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'direct'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">default:</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">direct</span><span class="p">,</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">direct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'bar'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">direct</span><span class="p">,</span><span class="w"> </span><span class="s1">'bar'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'direct'</span><span class="p">),</span><span class="w"> </span><span class="s1">'bar'</span></pre>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="define">define<span class="arg-list">(options)</span></h2>&#x000A;&#x000A;<h4 id="raises-an-error-if-name-is-missing">raises an error if name is missing</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'name'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="p">{}</span></pre>&#x000A;&#x000A;<h4 id="raises-an-error-if-the-description-option-is-missing">raises an error if the description option is missing</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'description'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'foo'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".definitions">.definitions</h2>&#x000A;&#x000A;<h4 id="is-a-table-of-the-current-definitions,-keyed-by-name">is a table of the current definitions, keyed by name</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'foo variable'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="n">var</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="nb">type</span><span class="p">(</span><span class="n">config</span><span class="p">.</span><span class="n">definitions</span><span class="p">),</span><span class="w"> </span><span class="s1">'table'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">var</span><span class="p">,</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">definitions</span><span class="p">.</span><span class="n">foo</span></pre>&#x000A;&#x000A;<h4 id="writing-directly-to-it-raises-an-error">writing directly to it raises an error</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">has_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">definitions</span><span class="p">.</span><span class="n">frob</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'crazy'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="set">set<span class="arg-list">(name, value)</span></h2>&#x000A;&#x000A;<h4 id="sets-&lt;name&gt;-globally-to-&lt;value&gt;">sets &lt;name&gt; globally to &lt;value&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'foo variable'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="n">var</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">),</span><span class="w"> </span><span class="mi">2</span></pre>&#x000A;&#x000A;<h4 id="an-error-is-raised-if-&lt;name&gt;-is-not-defined">an error is raised if &lt;name&gt; is not defined</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Undefined'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'que'</span><span class="p">,</span><span class="w"> </span><span class="s1">'si'</span></pre>&#x000A;&#x000A;<h4 id="setting-a-value-of-nil-clears-the-value">setting a value of nil clears the value</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'foo variable'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="n">var</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'bar'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">foo</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="get">get<span class="arg-list">(name)</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'var'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test variable'</span></pre>&#x000A;&#x000A;<h4 id="returns-the-global-value-of-&lt;name&gt;">returns the global value of &lt;name&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'var'</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'var'</span><span class="p">),</span><span class="w"> </span><span class="s1">'hello'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when a default is provided)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'with_default'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">default:</span><span class="w"> </span><span class="mi">123</span></pre>&#x000A;&#x000A;<h4 id="the-default-value-is-returned-if-no-value-has-been-set">the default value is returned if no value has been set</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'with_default'</span><span class="p">),</span><span class="w"> </span><span class="mi">123</span></pre>&#x000A;&#x000A;<h4 id="if-a-value-has-been-set-it-takes-precedence">if a value has been set it takes precedence</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'with_default'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'with_default'</span><span class="p">),</span><span class="w"> </span><span class="s1">'foo'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when a validate function is provided)</span></h3>&#x000A;&#x000A;<h4 id="is-called-with-the-value-to-be-set-whenever-the-variable-is-set">is called with the value to be set whenever the variable is set</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">validate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">:validate</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="s1">'my_value'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">validate</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="s1">'my_value'</span></pre>&#x000A;&#x000A;<h4 id="an-error-is-raised-if-the-function-returns-false-for-to-be-set-value">an error is raised if the function returns false for to-be set value</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">validate:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">validate:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">no_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">validate:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">no_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span></pre>&#x000A;&#x000A;<h4 id="an-error-is-not-raised-if-the-function-returns-truish-for-to-be-set-value">an error is not raised if the function returns truish for to-be set value</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">validate:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'validated'</span><span class="p">),</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">validate:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo2'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'validated'</span><span class="p">),</span><span class="w"> </span><span class="s1">'foo2'</span></pre>&#x000A;&#x000A;<h4 id="the-function-is-not-called-when-clearing-a-value-by-setting-it-to-nil">the function is not called when clearing a value by setting it to nil</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">validate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Spy</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">:validate</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'validated'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">validate</span><span class="p">.</span><span class="n">called</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when a convert function is provided)</span></h3>&#x000A;&#x000A;<h4 id="is-called-with-the-value-to-be-set-and-the-return-value-is-used-instead">is called with the value to be set and the return value is used instead</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'converted'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">convert:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'wanted'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'converted'</span><span class="p">,</span><span class="w"> </span><span class="s1">'requested'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">converted</span><span class="p">,</span><span class="w"> </span><span class="s1">'wanted'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when options is provided)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w">&#x000A;    </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'with_options'</span><span class="w">&#x000A;    </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="w">&#x000A;    </span><span class="ss">options:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="an-error-is-raised-if-the-to-be-set-value-is-not-a-valid-option">an error is raised if the to-be set value is not a valid option</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'option'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'with_options'</span><span class="p">,</span><span class="w"> </span><span class="s1">'three'</span></pre>&#x000A;&#x000A;<h4 id="an-error-is-not-raised-if-the-to-be-set-value-is-a-valid-option">an error is not raised if the to-be set value is a valid option</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'with_options'</span><span class="p">,</span><span class="w"> </span><span class="s1">'one'</span></pre>&#x000A;&#x000A;<h4 id="options-can-be-a-function-returning-a-table">options can be a function returning a table</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'with_options_func'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">options:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="w"> </span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'option'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'with_options_func'</span><span class="p">,</span><span class="w"> </span><span class="s1">'three'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'with_options_func'</span><span class="p">,</span><span class="w"> </span><span class="s1">'one'</span></pre>&#x000A;&#x000A;<h4 id="options-can-be-a-table-of-tables-containg-values-and-descriptions">options can be a table of tables containg values and descriptions</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">options</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="w"> </span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="s1">'description for one'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="p">{</span><span class="w"> </span><span class="s1">'two'</span><span class="p">,</span><span class="w"> </span><span class="s1">'description for two'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="p">}</span><span class="w">&#x000A;&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'with_options_desc'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">:options</span><span class="w">&#x000A;&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'option'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'with_options_desc'</span><span class="p">,</span><span class="w"> </span><span class="s1">'three'</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'with_options_desc'</span><span class="p">,</span><span class="w"> </span><span class="s1">'one'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when scope is provided)</span></h3>&#x000A;&#x000A;<h4 id="raises-an-error-if-it-is-not-&quot;local&quot;-or-&quot;global&quot;">raises an error if it is not &quot;local&quot; or &quot;global&quot;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'scope'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'bla'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">scope:</span><span class="w"> </span><span class="s1">'blarg'</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  with local scope for a variable)</span></h3>&#x000A;&#x000A;<h4 id="an-error-is-raised-when-trying-to-set-the-global-value-of-the-variable">an error is raised when trying to set the global value of the variable</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'local'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="ss">scope:</span><span class="w"> </span><span class="s1">'local'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'local'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when type_of is provided)</span></h3>&#x000A;&#x000A;<h4 id="raises-an-error-if-the-type-is-not-recognized">raises an error if the type is not recognized</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'type'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'bla'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">type_of:</span><span class="w"> </span><span class="s1">'blarg'</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  and is &quot;boolean&quot;)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">def</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'bool'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">type_of:</span><span class="w"> </span><span class="s1">'boolean'</span><span class="w">&#x000A;  </span><span class="n">def</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">definitions</span><span class="p">.</span><span class="n">bool</span></pre>&#x000A;&#x000A;<h4 id="options-are-{true,-false}">options are {true, false}</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">options</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="convert-handles-boolean-types-and-&quot;true&quot;-and-&quot;false&quot;">convert handles boolean types and &quot;true&quot; and &quot;false&quot;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="kc">true</span><span class="p">),</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="kc">false</span><span class="p">),</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="s1">'true'</span><span class="p">),</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="s1">'false'</span><span class="p">),</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="s1">'blargh'</span><span class="p">),</span><span class="w"> </span><span class="s1">'blargh'</span></pre>&#x000A;&#x000A;<h4 id="converts-to-boolean-upon-assignment">converts to boolean upon assignment</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">bool</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'false'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">bool</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  and is &quot;number&quot;)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">def</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'number'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">type_of:</span><span class="w"> </span><span class="s1">'number'</span><span class="w">&#x000A;  </span><span class="n">def</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">definitions</span><span class="p">.</span><span class="n">number</span></pre>&#x000A;&#x000A;<h4 id="convert-handles-numbers-and-string-numbers">convert handles numbers and string numbers</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="s1">'1'</span><span class="p">),</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="mi">0</span><span class="p">.</span><span class="mi">5</span><span class="p">),</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">5</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="s1">'0.5'</span><span class="p">),</span><span class="w"> </span><span class="mi">0</span><span class="p">.</span><span class="mi">5</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="p">(</span><span class="s1">'blargh'</span><span class="p">),</span><span class="w"> </span><span class="s1">'blargh'</span></pre>&#x000A;&#x000A;<h4 id="validate-returns-true-for-numbers-only">validate returns true for numbers only</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">validate</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">validate</span><span class="w"> </span><span class="mi">1</span><span class="p">.</span><span class="mi">2</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">validate</span><span class="w"> </span><span class="s1">'1'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">validate</span><span class="w"> </span><span class="s1">'blargh'</span></pre>&#x000A;&#x000A;<h4 id="converts-to-number-upon-assignment">converts to number upon assignment</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">number</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'1'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">number</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  and is &quot;string_list&quot;)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">def</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'string_list'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">type_of:</span><span class="w"> </span><span class="s1">'string_list'</span><span class="w">&#x000A;  </span><span class="n">def</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">definitions</span><span class="p">.</span><span class="n">string_list</span></pre>&#x000A;&#x000A;<h4 id="validate-returns-true-for-table-values">validate returns true for table values</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">validate</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">validate</span><span class="w"> </span><span class="s1">'1'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">validate</span><span class="w"> </span><span class="mi">23</span></pre>&#x000A;<div class="spec-group spec-group-4">&#x000A;&#x000A;<h4 id="convert">convert</h4>&#x000A;&#x000A;<h4 id="leaves-string-tables-alone">leaves string tables alone</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">orig</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'hi'</span><span class="p">,</span><span class="w"> </span><span class="s1">'there'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">orig</span><span class="p">,</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="w"> </span><span class="n">orig</span></pre>&#x000A;&#x000A;<h4 id="converts-values-in-other-tables-as-necessary">converts values in other tables as necessary</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">orig</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'1'</span><span class="p">,</span><span class="w"> </span><span class="s1">'2'</span><span class="p">,</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="w"> </span><span class="n">orig</span></pre>&#x000A;&#x000A;<h4 id="converts-simple-values-into-a-table">converts simple values into a table</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'1'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="w"> </span><span class="s1">'1'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'1'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="w"> </span><span class="mi">1</span></pre>&#x000A;&#x000A;<h4 id="converts-a-blank-string-into-an-empty-table">converts a blank string into an empty table</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="w"> </span><span class="s1">''</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="w"> </span><span class="s1">'  '</span></pre>&#x000A;&#x000A;<h4 id="converts-a-comma-separated-string-into-a-list-of-values">converts a comma separated string into a list of values</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'1'</span><span class="p">,</span><span class="w"> </span><span class="s1">'2'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="w"> </span><span class="s1">'1,2'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'1'</span><span class="p">,</span><span class="w"> </span><span class="s1">'2'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">def</span><span class="p">.</span><span class="n">convert</span><span class="w"> </span><span class="s1">' 1 ,   2 '</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(watching)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'trigger'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'watchable'</span></pre>&#x000A;&#x000A;<h4 id="watch(name,-function)-register-a-watcher-for-&lt;name&gt;">watch(name, function) register a watcher for &lt;name&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">not_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">watch</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span></pre>&#x000A;&#x000A;<h4 id="set-invokes-watchers-with-&lt;name&gt;,-&lt;value&gt;-and-false">set invokes watchers with &lt;name&gt;, &lt;value&gt; and false</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">callback</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Spy</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">watch</span><span class="w"> </span><span class="s1">'trigger'</span><span class="p">,</span><span class="w"> </span><span class="n">callback</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'trigger'</span><span class="p">,</span><span class="w"> </span><span class="s1">'value'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">callback</span><span class="p">.</span><span class="n">called_with</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'trigger'</span><span class="p">,</span><span class="w"> </span><span class="s1">'value'</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="define(..)-invokes-watchers-with-&lt;name&gt;,-&lt;default-value&gt;-and-false">define(..) invokes watchers with &lt;name&gt;, &lt;default-value&gt; and false</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">callback</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">watch</span><span class="w"> </span><span class="s1">'undefined'</span><span class="p">,</span><span class="w"> </span><span class="n">callback</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'undefined'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'springs into life'</span><span class="p">,</span><span class="w"> </span><span class="ss">default:</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">callback</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="s1">'undefined'</span><span class="p">,</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(..  when a callback raises an error)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">watch</span><span class="w"> </span><span class="s1">'trigger'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nb">error</span><span class="w"> </span><span class="s1">'oh noes'</span></pre>&#x000A;&#x000A;<h4 id="other-callbacks-are-still-invoked">other callbacks are still invoked</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">callback</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Spy</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">watch</span><span class="w"> </span><span class="s1">'trigger'</span><span class="p">,</span><span class="w"> </span><span class="n">callback</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'trigger'</span><span class="p">,</span><span class="w"> </span><span class="s1">'value'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">callback</span><span class="p">.</span><span class="n">called</span></pre>&#x000A;&#x000A;<h4 id="an-error-is-logged">an error is logged</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">set</span><span class="w"> </span><span class="s1">'trigger'</span><span class="p">,</span><span class="w"> </span><span class="s1">'value'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">match</span><span class="w"> </span><span class="n">log</span><span class="p">.</span><span class="n">last_error</span><span class="p">.</span><span class="n">message</span><span class="p">,</span><span class="w"> </span><span class="s1">'watcher'</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="proxy">proxy</h2>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'my_var'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'base'</span><span class="p">,</span><span class="w"> </span><span class="ss">type_of:</span><span class="w"> </span><span class="s1">'number'</span><span class="w">&#x000A;</span><span class="kd">local</span><span class="w"> </span><span class="n">proxy</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">my_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A;  </span><span class="n">proxy</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">local_proxy</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="returns-a-table-with-access-to-all-previously-defined-variables">returns a table with access to all previously defined variables</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span></pre>&#x000A;&#x000A;<h4 id="changing-a-variable-changes-it-locally-only">changing a variable changes it locally only</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">321</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">321</span><span class="p">,</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">my_var</span></pre>&#x000A;&#x000A;<h4 id="assignments-are-still-validated-and-converted-as-usual">assignments are still validated and converted as usual</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">has_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'not a number'</span><span class="w">&#x000A;</span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'111'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">111</span><span class="p">,</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span></pre>&#x000A;&#x000A;<h4 id="an-error-is-raised-if-trying-to-set-a-variable-with-global-scope">an error is raised if trying to set a variable with global scope</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'global'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'global'</span><span class="p">,</span><span class="w"> </span><span class="ss">scope:</span><span class="w"> </span><span class="s1">'global'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">has_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">global</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'illegal'</span></pre>&#x000A;&#x000A;<h4 id="an-error-is-raised-if-the-variable-is-not-defined">an error is raised if the variable is not defined</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Undefined'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">que</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'si'</span></pre>&#x000A;&#x000A;<h4 id="setting-a-value-to-nil-clears-the-value">setting a value to nil clears the value</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">666</span><span class="w">&#x000A;</span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span></pre>&#x000A;&#x000A;<h4 id="setting-a-variable-via-a-proxy-invokes-watchers-with-&lt;name&gt;,-&lt;value&gt;-and-true">setting a variable via a proxy invokes watchers with &lt;name&gt;, &lt;value&gt; and true</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">callback</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;</span><span class="n">config</span><span class="p">.</span><span class="n">watch</span><span class="w"> </span><span class="s1">'my_var'</span><span class="p">,</span><span class="w"> </span><span class="n">callback</span><span class="w">&#x000A;</span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">333</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">callback</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'my_var'</span><span class="p">,</span><span class="w"> </span><span class="mi">333</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="can-be-chained-to-another-proxy-to-create-a-lookup-chain">can be chained to another proxy to create a lookup chain</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">my_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">222</span><span class="w">&#x000A;</span><span class="n">base_proxy</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">local_proxy</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">proxy</span><span class="p">.</span><span class="n">chain_to</span><span class="w"> </span><span class="n">base_proxy</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">222</span><span class="p">,</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w">&#x000A;</span><span class="n">base_proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">333</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">333</span><span class="p">,</span><span class="w"> </span><span class="n">proxy</span><span class="p">.</span><span class="n">my_var</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">222</span><span class="p">,</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">my_var</span></pre>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2016
            <a class='alert-link' href='https://github.com/howl-editor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
